﻿using System;
using System.Windows.Forms;

namespace WindowsAPI
{
    public class LambdaMessageFilter : IMessageFilter
    {
        /* ------------------------------------------------------------------------------------------ */

        private Predicate<Message> f_Filter;

        /* ------------------------------------------------------------------------------------------ */

        public Predicate<Message> Filter { get { return f_Filter; } set { f_Filter = value; } }

        /* ------------------------------------------------------------------------------------------ */

        public LambdaMessageFilter(Predicate<Message> Filter) { f_Filter = Filter; }

        /* ------------------------------------------------------------------------------------------ */

        public bool PreFilterMessage(ref Message m) { var filter = f_Filter; return filter == null || filter(m); }

        /* ------------------------------------------------------------------------------------------ */
    }
}
